import 'package:flutter/material.dart';
import 'package:flutter_demo3/util/my_colors.dart';

class PostItem extends StatefulWidget {
  String _imgSrc;
  String _content;
  String _userHeadSrc;
  String _userName;
  int _likesNum;

  PostItem(this._imgSrc, this._content, this._userHeadSrc, this._userName,
      this._likesNum);

  @override
  _PostItemState createState() => _PostItemState(this._imgSrc, this._content,
      this._userHeadSrc, this._userName, this._likesNum);
}

class _PostItemState extends State<PostItem> {
  String _imgSrc;
  String _content;
  String _userHeadSrc;
  String _userName;
  int _likesNum;
  final double _user_head_radius = 30.0;
  double _item_width;

  _PostItemState(this._imgSrc, this._content, this._userHeadSrc, this._userName,
      this._likesNum);

  @override
  Widget build(BuildContext context) {
    _item_width = MediaQuery.of(context).size.width / 2 - 10;
    return Container(

      child: Column(
        children: <Widget>[
          Image.network(_imgSrc, width: _item_width),
          Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadiusDirectional.circular(20),
                color: MyColors.subColor
              ),
              width: _item_width,
              height: MediaQuery.of(context).size.height / 13,
              child: Stack(
                children: <Widget>[
                  //内容预览
                  Align(
                      child: Text(
                        _content,
                        maxLines: 2,
                        style: TextStyle(fontSize: 13),
                      ),
                      alignment: Alignment.topLeft),

                  //用户头像与名称
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Align(
                        child: Row(
                          children: <Widget>[
                            ClipOval(
                              child: Image.network(
                                _userHeadSrc,
                                width: _user_head_radius,
                                height: _user_head_radius,
                              ),
                            ),
                            Padding(
                              padding: EdgeInsets.fromLTRB(5, 0, 0, 0),
                              child: Text(_userName),
                            ),
                          ],
                        ),
                        alignment: Alignment.bottomLeft),
                  ),

                  //点赞图标与点赞数
                  Align(
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          IconButton(
                            icon: Icon(
                              Icons.thumb_up,
                              size: 20,
                            ),
                            onPressed: () {},
                          ),
                          Text(
                            _likesNum.toString(),
                            style:
                                TextStyle(fontSize: 10, color: Colors.black38),
                          )
                        ],
                      ),
                      alignment: Alignment.bottomRight),
                ],
              ))
        ],
      ),
    );
  }
}
